<style lang="less">
.id_img_wp{
    width:100%;
    min-height:30px;
  }
  .img_wp{
    width:195px;
    margin:0 10px;
    float:left;
    cursor:pointer;
  }
  .img_wp:first-child{
    margin-left: 100px;
    margin-top: 19px;
  }
  .img_wp img{
    width:100%;
    height:125px;
    border:1px dotted #d7d7d7;
  }
  .img_intro{
    color:#EB9620;
    text-align:center;
    font-family:"微软雅黑";
    padding:10px 0 10px 0;
  }
</style>
<template>
  <div class="search">
    <Row>
      <i-col>
        <Card>
          <Row>
            <Form ref="searchForm" :model="searchForm" inline :label-width="110" class="search-form">
              <Row>
                <i-col span="8">
                  <Form-item label="真实姓名:" prop="userRealName">
                    <Input type="text" v-model="searchForm.userRealName" clearable placeholder="请输入真实姓名"
                      style="width: 200px" />
                  </Form-item>
                </i-col>
                <i-col span="8">
                  <Form-item label="手机号:" prop="searchPhone">
                    <Input type="text" v-model="searchForm.searchPhone" clearable placeholder="请输入手机号" maxlength="11"
                      style="width: 200px" />
                  </Form-item>
                </i-col>
                <i-col span="8">
                  <Form-item label="邮箱:" prop="searchEmail">
                    <Input type="text" v-model="searchForm.searchEmail" clearable placeholder="请输入邮箱"
                      style="width: 200px" />
                  </Form-item>
                </i-col>
              </Row>

              <Row class="operation">
                <i-col span="8">
                  <Form-item label="所属部门:" prop="any">
                    <Cascader style="width: 200px" :data="department" :load-data="loadData" @on-change="handleChangeDep"  @on-clear="clearDepId"
                      change-on-select filterable v-model="searchForm.any"></Cascader>
                  </Form-item>
                </i-col>
                <i-col span="8">
                  <Form-item label="状态:" prop="lockFlag">
                    <Select v-model="searchForm.lockFlag" placeholder="请选择状态" clearable style="width: 200px">
                      <Option value="0">启用</Option>
                      <Option value="9">禁用</Option>
                    </Select>
                  </Form-item>
                </i-col>
                <i-col span="8">
                  <Form-item label="创建时间">
                    <DatePicker v-model="searchForm.createTimes" type="daterange" format="yyyy-MM-dd" clearable
                      @on-change="selectDateRange" placeholder="选择起始时间" style="width: 200px"></DatePicker>
                  </Form-item>
                </i-col>
              </Row>

              <Row class="operation" style="text-align: center">
                <Form-item style="margin-left:-35px;" class="br">
                  <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                  <Button @click="handleReset" icon="md-redo">重置</Button>

                </Form-item>
              </Row>
            </Form>
          </Row>
          <Row class="operation">
            <Button @click="add" type="primary" icon="md-add">新增</Button>
            <Button @click="upAll" icon="md-remove-circle">批量停用</Button>
          </Row>
          <Row style="margin-top: 10px;">
            <Alert show-icon>
              已选择 <span class="select-count">{{selectCount}}</span> 项
              <a class="select-clear" @click="clearSelectAll">清空</a>
            </Alert>
          </Row>
          <Row>
            <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" 
              @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table">
              <template slot-scope="{ row }" slot="lockFlag">
                <tag v-if="row.lockFlag=='0'" color="success" size="default">启用</tag>
                <tag v-if="row.lockFlag=='9'" color="warning" size="default">禁用</tag>
              </template>

              <template slot-scope="{ row }" slot="newStatus">
                <tag v-if="row.newStatus=='00'" color="success" size="default">通过</tag>
                <tag v-if="row.newStatus=='01'" color="primary" size="default">审核中</tag>
                <tag v-if="row.newStatus=='04'" color="warning" size="default">拒绝</tag>
                <tag v-if="row.newStatus=='10'" color="primary" size="default">变更中</tag>

              </template>

              <template slot-scope="{ row }" slot="oldStatus">
                <tag v-if="row.oldStatus=='00'" color="success" size="default">通过</tag>
                <tag v-if="row.oldStatus=='01'" color="primary" size="default">审核中</tag>
                <tag v-if="row.oldStatus=='04'" color="warning" size="default">拒绝</tag>
                <tag v-if="row.oldStatus=='10'" color="primary" size="default">变更中</tag>
              </template>

              <template slot-scope="{ row }" slot="newDataId">
                <span v-if="row.newDataId!=null&&row.newDataId!=undefined&&row.newDataId!=''&&row.oldDataId!=null&&row.oldDataId!=''&&row.oldDataId!=undefined">
                  新车：{{row.newDataId}}，二手车：{{row.oldDataId}}
                </span>
                <span v-if="row.newDataId!=null&&row.newDataId!=undefined&&row.newDataId!=''&&(row.oldDataId==null||row.oldDataId==''||row.oldDataId!=undefined)">
                  新车：{{row.newDataId}}
                </span>
                <span v-if="(row.newDataId==null||row.newDataId==undefined||row.newDataId=='')&&row.oldDataId!=null&&row.oldDataId!=''&&row.oldDataId!=undefined">
                  二手车：{{row.oldDataId}}
                </span>

              </template>

              <template slot-scope="{ row }" slot="action">
                <span v-if="userId==row.userId">
                  <Button disabled style="margin-right:5px" type="primary" size="small" @click="edit(row)">编辑 </Button>
                </span>
                <span v-if="userId!=row.userId">
                  <Button  style="margin-right:5px" type="primary" size="small" @click="edit(row)">编辑</Button>
                  <!-- <span v-if="row.newStatus=='01'||row.newStatus=='10'||row.oldStatus=='01'||row.oldStatus=='10'">
                    <Button disabled style="margin-right:5px" type="primary" size="small" @click="edit(row)">编辑</Button>
                  </span>
                  <span v-if="row.newStatus!='01'&&row.newStatus!='10'&&row.oldStatus!='01'&&row.oldStatus!='10'">
                    <Button style="margin-right:5px" type="primary" size="small" @click="edit(row)">编辑</Button>
                  </span> -->
                </span>

                <span v-if="'0'==row.lockFlag">
                  <Button style="margin-right:5px" type="primary" size="small" @click="passWord(row)">重置密码
                  </Button>
                </span>
                <span v-if="'0'!=row.lockFlag">
                  <Button disabled style="margin-right:5px" type="primary" size="small" @click="passWord(row)">重置密码
                  </Button>
                </span>
              </template>
            </Table>
          </Row>
          <Row type="flex" justify="end" class="page">
            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" style="margin-top: 10px;"
              @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small"
              show-total show-elevator show-sizer></Page>
          </Row>
        </Card>
      </i-col>
    </Row>

    <Modal :title="modalTitle" v-model="userModalVisible" :mask-closable='false' :width="1200" :styles="{top: '90px'}">
      <Form ref="userForm" :model="userForm" :label-width="100" :rules="userFormValidate">
        <Row>
          <i-col span="12">
            <FormItem label="真实姓名" prop="userRealName">
              <Input v-model="userForm.userRealName"  clearable style="width: 300px" />
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="所属部门" prop="departmentTitle">
              <Poptip trigger="click" placement="right" title="选择部门">
                <div style="display:flex;" >
                  <Input v-model="userForm.departmentTitle" disabled clearable readonly style="margin-right:10px;width: 300px"
                    @on-clear="channelClear" />
                  <Button icon="md-trash" @click="clearSelectDep">选择部门</Button>
                </div>
                <div slot="content" class="tree-bar" style="height: 200px;  overflow-y: auto;">
                  <Input v-model="searchKey" suffix="ios-search" @on-change="searchDp" placeholder="输入部门名搜索" />
                  <Tree :data="department" :load-data="loadDataTree" @on-select-change="selectTree"></Tree>
                  <Spin size="large" fix v-if="dpLoading"></Spin>
                </div>
              </Poptip>
            </FormItem>
          </i-col>
        </Row>

        <Row>
          <i-col span="12">
            <FormItem label="用户名" prop="username">
              <Input v-model="userForm.username" v-bind:disabled="this.modalType=='1'" clearable style="width: 300px" />
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="邮箱" prop="userEmail">
              <Input v-model="userForm.userEmail" clearable style="width: 300px" />
            </FormItem>
          </i-col>
        </Row>

        <Row>
          <i-col span="12">
            <FormItem label="手机号" prop="phone">
              <Input v-model="userForm.phone" clearable style="width: 300px" maxlength="11" />
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="身份证" prop="identityNumber">
              <Input v-model="userForm.identityNumber" v-bind:disabled="this.modalType=='1'" clearable style="width: 300px" maxlength="18" />
            </FormItem>
          </i-col>
        </Row>
        <!-- 仅仅有新车 -->
        <Row v-if="this.newRoleList.length>0&&this.oldRoleList.length==0">
          <i-col span="24">
            <FormItem label="角色" prop="border">
              <CheckboxGroup v-model="border" @on-change="chooseRole">
                <Checkbox v-for="item in newRoleList" :value="item.id" :key="item.id" :label="item.id" border>
                  {{item.roleName}} </Checkbox>
              </CheckboxGroup>
            </FormItem>
          </i-col>
        </Row>
        <!-- 仅仅有二手车 -->
        <Row v-if="this.newRoleList.length==0&&this.oldRoleList.length>0">
          <i-col span="24">
            <FormItem label="角色" prop="tBorder">
              <CheckboxGroup v-model="tBorder" @on-change="chooseOldRole">
                <Checkbox v-for="item in oldRoleList" :value="item.id" :key="item.id" :label="item.id" border>
                  {{item.roleName}} </Checkbox>
              </CheckboxGroup>
            </FormItem>
          </i-col>
        </Row>
        <!-- 新车二手车都有 -->
        <Row v-if="this.newRoleList.length>0&&this.oldRoleList.length>0">
          <i-col span="24">
            <FormItem label="角色" prop="border">
              <CheckboxGroup v-model="border" @on-change="chooseRole">
                <Checkbox v-for="item in newRoleList" :value="item.id" :key="item.id" :label="item.id" border>
                  {{item.roleName}} </Checkbox>
              </CheckboxGroup>
            </FormItem>
          </i-col>
          <i-col span="24">
            <FormItem label="" prop="tBorder">
              <CheckboxGroup v-model="tBorder" @on-change="chooseOldRole">
                <Checkbox v-for="item in oldRoleList" :value="item.id" :key="item.id" :label="item.id" border>
                  {{item.roleName}} </Checkbox>
              </CheckboxGroup>
            </FormItem>
          </i-col>
        </Row>

      <Row >
        <i-col span="20">
            <FormItem label="身份证上传" prop="imgzurl">
              <div  class="over mt10" style="border: 1px solid #e4e8f3;">
                <div class="id_img_wp">
                    <input type="file" accept="image/*" @change="getImg($event,'zm')"  v-show="false" value="" ref="img_z"/>
                    <div style="overflow: hidden;">
                      <div class="img_wp" @click="zhengmian">
                          <img :src="userForm.imgzurl" id="zmz" v-if="userForm.imgzurl"/>
                          <img v-else src="../../../../../../src/assets/images/zhengmian@2x.png"/>
                          <p class="img_intro">身份证人像面</p>
                      </div>
                      <div class="img_wp" style="text-align: right;font-size: 18px;margin-top: 20px">
                        最佳拍摄示意
                      </div>
                      <div class="img_wp">
                          <div style="margin-top: 19px;margin-left: 20px">

                          <img  src="../../../../../../src/assets/images/user/user001.png"/>
                          </div>

                      </div>
                  </div>
                </div>
                <div class="id_img_wp">
                  <div style="overflow: hidden;">
                    <div style="margin:0 10px;float:left; cursor:pointer;margin-left: 60px;">
                        <img  src="../../../../../../src/assets/images/user/user002.png"/>
                        <div style="color: rgb(74, 74, 73); font-family:'微软雅黑'; text-align:center;">
                          <div style="float:left; cursor:pointer;margin-top: 2px; margin-left: 18px;">
                            <img src="../../../../../../src/assets/images/user/cuowu.png" />
                          </div>&nbsp;不要倾斜拍摄
                        </div>
                    </div>
                    <div style="margin:0 10px 0 60px;float:left; cursor:pointer ;">
                        <img  src="../../../../../../src/assets/images/user/user003.png"/>
                        <div style="color: rgb(74, 74, 73); font-family:'微软雅黑'; text-align:center;">
                          <div style="float:left; cursor:pointer;margin-top: 2px; margin-left: 18px;">
                            <img src="../../../../../../src/assets/images/user/cuowu.png" />
                          </div>&nbsp;不要超出屏幕
                        </div>
                    </div>
                    <div style="margin:0 10px 0 60px;float:left; cursor:pointer;">
                        <img  src="../../../../../../src/assets/images/user/user004.png"/>
                        <div style="color: rgb(74, 74, 73); font-family:'微软雅黑'; text-align:center;">
                          <div style="float:left; cursor:pointer;margin-top: 2px; margin-left: 18px;">
                            <img src="../../../../../../src/assets/images/user/cuowu.png" />
                            </div>&nbsp;不要有倾斜角度
                        </div>
                    </div>
                    <div style="margin:0 10px 0 60px;float:left; cursor:pointer;">
                        <img  src="../../../../../../src/assets/images/user/user005.png"/>
                        <div style="color: rgb(74, 74, 73); font-family:'微软雅黑'; text-align:center;">
                          <div style="float:left; cursor:pointer;margin-top: 2px; margin-left: 18px;">
                            <img src="../../../../../../src/assets/images/user/cuowu.png" />
                            </div>&nbsp;不要离摄像头太远
                        </div>
                    </div>
                  </div>

                </div>
            </div>

            </FormItem>
          </i-col>
      </Row>
      </Form>

      <!-- <Button @click="openFileUpload" size="large" style="margin-left: 45%;color: #2b85e4;   background-color:white;border: none">上传身份证</Button> -->
      <!-- <div v-if="isShowFile" > -->
            <!--附件-->
            <!-- <file-operation  :uploadParam="uploadParam" :isInt="canUpload" :path="path"  ></file-operation> -->
        <!-- </div> -->
      <div slot="footer">
        <Button type="text" @click="cancelUser">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="submitUser">提交</Button>
      </div>
    </Modal>

    <Modal :title="modalTitle" v-model="userModalVisibleSee" :mask-closable='false' :width="1200" :styles="{top: '90px'}">
      <Form ref="userForm" :model="userForm" :label-width="100" :rules="userFormValidate">
        <Row>
          <i-col span="12">
            <FormItem label="真实姓名" prop="userRealName">
              <Input v-model="userForm.userRealName" disabled clearable style="width: 300px" />
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="所属部门" prop="departmentTitle">
              <Poptip trigger="click" placement="right" title="选择部门">
                <div style="display:flex;" >
                  <Input v-model="userForm.departmentTitle" disabled readonly style="margin-right:10px;width: 300px"
                    @on-clear="channelClear" />
                </div>

              </Poptip>
            </FormItem>
          </i-col>
        </Row>

        <Row>
          <i-col span="12">
            <FormItem label="用户名" prop="username">
              <Input v-model="userForm.username" disabled clearable style="width: 300px" />
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="邮箱" prop="userEmail">
              <Input v-model="userForm.userEmail" disabled clearable style="width: 300px" />
            </FormItem>
          </i-col>
        </Row>

        <Row>
          <i-col span="12">
            <FormItem label="手机号" prop="phone">
              <Input v-model="userForm.phone" disabled clearable style="width: 300px" />
            </FormItem>
          </i-col>
          <i-col span="12">
            <FormItem label="身份证" prop="identityNumber">
              <Input v-model="userForm.identityNumber" disabled clearable style="width: 300px" />
            </FormItem>
          </i-col>
        </Row>
        <!-- 仅仅有新车 -->
        <Row v-if="this.newRoleList.length>0&&this.oldRoleList.length==0">
          <i-col span="24">
            <FormItem label="角色" prop="border">
              <CheckboxGroup v-model="border" @on-change="chooseRole">
                <Checkbox v-for="item in newRoleList" :value="item.id" :key="item.id" :label="item.id" border disabled>
                  {{item.roleName}} </Checkbox>
              </CheckboxGroup>
            </FormItem>
          </i-col>
        </Row>
        <!-- 仅仅有二手车 -->
        <Row v-if="this.newRoleList.length==0&&this.oldRoleList.length>0">
          <i-col span="24">
            <FormItem label="角色" prop="tBorder">
              <CheckboxGroup v-model="tBorder" @on-change="chooseOldRole">
                <Checkbox v-for="item in oldRoleList" :value="item.id" :key="item.id" :label="item.id" border disabled>
                  {{item.roleName}} </Checkbox>
              </CheckboxGroup>
            </FormItem>
          </i-col>
        </Row>
        <!-- 新车二手车都有 -->
        <Row v-if="this.newRoleList.length>0&&this.oldRoleList.length>0">
          <i-col span="24">
            <FormItem label="角色" prop="border">
              <CheckboxGroup v-model="border" @on-change="chooseRole">
                <Checkbox v-for="item in newRoleList" :value="item.id" :key="item.id" :label="item.id" border disabled>
                  {{item.roleName}} </Checkbox>
              </CheckboxGroup>
            </FormItem>
          </i-col>
          <i-col span="24">
            <FormItem label="" prop="tBorder">
              <CheckboxGroup v-model="tBorder" @on-change="chooseOldRole">
                <Checkbox v-for="item in oldRoleList" :value="item.id" :key="item.id" :label="item.id" border disabled>
                  {{item.roleName}} </Checkbox>
              </CheckboxGroup>
            </FormItem>
          </i-col>
        </Row>

      <Row >
        <i-col span="20">
            <FormItem label="身份证上传" prop="imgzurl">
              <div  class="over mt10" style="border: 1px solid #e4e8f3;">
                <div class="id_img_wp">
                    <div style="overflow: hidden;">
                      <div class="img_wp" >
                          <img :src="userForm.imgzurl" id="zmz" v-if="userForm.imgzurl"/>
                          <img v-else src="../../../../../../src/assets/images/zhengmian@2x.png"/>
                          <p class="img_intro">身份证人像面</p>
                      </div>
                      <div class="img_wp" style="text-align: right;font-size: 18px;margin-top: 20px">
                        最佳拍摄示意
                      </div>
                      <div class="img_wp">
                          <div style="margin-top: 19px;margin-left: 20px">

                          <img  src="../../../../../../src/assets/images/user/user001.png"/>
                          </div>

                      </div>
                  </div>
                </div>
                <div class="id_img_wp">
                  <div style="overflow: hidden;">
                    <div style="margin:0 10px;float:left; cursor:pointer;margin-left: 60px;">
                        <img  src="../../../../../../src/assets/images/user/user002.png"/>
                        <div style="color: rgb(74, 74, 73); font-family:'微软雅黑'; text-align:center;">
                          <div style="float:left; cursor:pointer;margin-top: 2px; margin-left: 18px;">
                            <img src="../../../../../../src/assets/images/user/cuowu.png" />
                          </div>&nbsp;不要倾斜拍摄
                        </div>
                    </div>
                    <div style="margin:0 10px 0 60px;float:left; cursor:pointer ;">
                        <img  src="../../../../../../src/assets/images/user/user003.png"/>
                        <div style="color: rgb(74, 74, 73); font-family:'微软雅黑'; text-align:center;">
                          <div style="float:left; cursor:pointer;margin-top: 2px; margin-left: 18px;">
                            <img src="../../../../../../src/assets/images/user/cuowu.png" />
                          </div>&nbsp;不要超出屏幕
                        </div>
                    </div>
                    <div style="margin:0 10px 0 60px;float:left; cursor:pointer;">
                        <img  src="../../../../../../src/assets/images/user/user004.png"/>
                        <div style="color: rgb(74, 74, 73); font-family:'微软雅黑'; text-align:center;">
                          <div style="float:left; cursor:pointer;margin-top: 2px; margin-left: 18px;">
                            <img src="../../../../../../src/assets/images/user/cuowu.png" />
                            </div>&nbsp;不要有倾斜角度
                        </div>
                    </div>
                    <div style="margin:0 10px 0 60px;float:left; cursor:pointer;">
                        <img  src="../../../../../../src/assets/images/user/user005.png"/>
                        <div style="color: rgb(74, 74, 73); font-family:'微软雅黑'; text-align:center;">
                          <div style="float:left; cursor:pointer;margin-top: 2px; margin-left: 18px;">
                            <img src="../../../../../../src/assets/images/user/cuowu.png" />
                            </div>&nbsp;不要离摄像头太远
                        </div>
                    </div>
                  </div>

                </div>
            </div>

            </FormItem>
          </i-col>
      </Row>
      </Form>
      <div slot="footer">

      </div>
    </Modal>
  </div>

</template>

<script>
import userDefine from "./user-define";
import {
  addUser,
  editUserTemp,
  enableUser,
  deleteUser,
  disableUser,
  getUserListDataTemp,
  upAllByIds,
  passWord,
  getUserPhotoByMD5
} from "_p/afs-apply/api/apply-admin/manage-user/user";

import {
  getDeptByParentId,
  searchDepartment,
  channelSearch,
  getDeptByDeptId,
} from "_p/afs-apply/api/apply-admin/department/department";

import {
  initAll,
  initAppertainRegion,
  searchAppertainRegion
} from "_p/afs-apply/api/apply-admin/appertain-region/appertainRegion";

import {
  getAllRoleList,
  getMatchingRole,
  getApplyAllList,
  getUserRole,
  getCommissionLoan
} from "_p/afs-apply/api/apply-admin/role/role";

import { deepClone } from "@/libs/utils/ObjectClone";
import * as utils from "@/projects/afs-apply/assets/js/utils";
import {checkBlack} from "@/projects/afs-apply/api/affiliation/affiliationAddEdit";
import FileOperation from "_p/basic/pages/image/upload-file/fileOperation.vue";

import {uploadFile, uploadRealFile,getBaseByMD5,getOCRInfo} from "_p/afs-apply/api/apply-contract/contract/entry/contract-img-upload";
import { getUri } from "@/libs/tools";
import {
        checkFile,
    } from "_p/basic/api/image/image-upload";

export default {
  name: "list-record",
  components: {
    FileOperation
  },
  data() {
    // 判断身份证号
    const validatePassword = (rule, value, callback) => {
      utils.doValidID(rule, value, callback);
    };
    // 判断手机号
    const validateMobile = (rule, value, callback) => {
      var reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
      if (!reg.test(value)) {
        callback(new Error("手机号格式错误"));
      } else {
        callback();
      }
    };

    const valiUsername = (rule, value, callback) => {
      var reg = /^[a-zA-Z0-9_]{6,18}$/;
      if (!reg.test(value)) {
        callback(new Error("6到18位（字母，数字，下划线）"));
      } else {
        callback();
      }
    };

    return {
      // 声明佣金和贷后的id
      commission:null,  // 佣金
      loan:null, // 贷后

      // 下面是用于附件
      path:"apply",
      isShowFile:false,
      canUpload:false,
      uploadParam: {
                busiNo: "",
                belongNo: "",
                busiType: "",
                busiData: {}
            },
      dpLoading: false, // 部门树加载
      submitLoading: false, // 提交的时候转圈圈

      modalType: 0, // 判断是新增还是修改

      userId: 0, // 登录用户id
      loading: true, // 应该是转圈圈的
      operationLoading: false, // 应该是也转圈圈的
      selectCount: 0, // 搜索选择的数量
      selectList: [], //  复选框  选中的集合
      // 搜索的集合
      searchForm: {
        createTimes: [], // 创建时间
        deptId: "", // 车辆类型 乘用车/商用车
        lockFlag: "", // 状态
        searchEmail: "", // 邮箱
        searchPhone: "", // 手机号
        userRealName: "", // 真实姓名
        pageNumber: 1,
        pageSize: 10,
        startDate: "",
        endDate: "",

        any:[],
      },
      selectDate: null, // 时间选择器
      department: [], // 这个是部门的集合
      userRole:[], // 这个渠道的所有角色名称

      // 查看的弹窗
      userModalVisibleSee:false,
      // 下面是关于弹出框的
      userModalVisible: false,
      modalTitle: "", // 弹出框上面的名字
      searchKey: "", // 这是部门搜索的时候用的
      userForm: {
        userId: "",
        userRealName: "", // 真实姓名
        departmentTitle: "", // 部门的名字
        deptId: "", //所属部门id
        username: "", //用户名
        userEmail: "", // 邮箱
        phone: "", // 手机号
        identityNumber: "", //身份证号
        newRoleIds: [], // 新车的角色集合
        oldRoleIds: [], //二手车的角色集合
        // 下面是用于上传图片
        imgfurl:"",
        imgzurl:"",
        finalimgList:[
          {
            fileName:"",
            isFastDFS:"",
            md5:"",
            size:"",
            suffix:""
          }
        ],
      },
      // 角色列表集合
      roleList: [],
      newRoleList: [], // 新车的角色
      oldRoleList: [], // 二手车角色
      deptId: "", // 这个是用于判断有没有选择角色

      // 下面是测试选择那些框
      border: [], // 这个没啥用测试复选框的时候用的
      oldBorder: [], // 存放老的集合用于对比

      //下面是放二手车的
      tBorder: [], //二手车的集合
      tOldBorder: [], // 二手车老数据集合
      userFormValidate: {
        userRealName: [
          { required: true, message: "真实姓名不能为空", trigger: "blur" }
        ],
        departmentTitle: [
          { required: true, message: "请选择所属部门", trigger: "blur" }
        ],
        username: [
          { required: true, message: "用户名不能为空", trigger: "blur" },
          { validator: valiUsername, trigger: "blur" }
        ],
        userEmail: [
          { required: false, message: "请输入邮箱地址" },
          { type: "email", message: "邮箱格式不正确" }
        ],
        phone: [
          { required: true, message: "手机号不能为空", trigger: "blur" },
          { validator: validateMobile, trigger: "blur" }
        ],
        identityNumber: [
          { required: true, message: "身份证不能为空", trigger: "blur" },
          { validator: validatePassword, trigger: "blur" }
        ],
        imgzurl: [
          { required: true, message: "请上传照片", trigger: "blur" },
        ]
      },

      columns: [
        {
          type: "selection",
          minWidth: 60,
          maxWidth: 60,
          align: "center",
          fixed: "left",
          _disabled: true
        },
        {
          title: "序号",
          type: "index",
          minWidth: 80,
          align: "center",
          fixed: "left"
        },
        {
          title: "真实姓名",
          key: "userRealName",
          align: "center",
          minWidth: 200,
          fixed: "left"
        },
        {
          title: "用户名",
          key: "username",
          align: "center",
          minWidth: 145,
          ellipsis: true, // 开启后，文本将不换行，超出部分显示为省略号
          tooltip: true // 鼠标放上去提示

        },
        {
          title: "新车审核状态",
          key: "newStatus",
          align: "center", // 设置剧中
          minWidth: 130,
          slot: "newStatus" // 锁定标志   table 里回找到这个同名参数  进行关联
        },
        {
          title: "二手车审核状态",
          key: "oldStatus",
          align: "center", // 设置剧中
          minWidth: 130,
          slot: "oldStatus" // 锁定标志   table 里回找到这个同名参数  进行关联
        },
        {
          title: "角色",
          key: "roleName",
          align: "center",
          minWidth: 145,
          ellipsis: true, // 开启后，文本将不换行，超出部分显示为省略号
          tooltip: true, // 鼠标放上去提示
        },
        {
          title: "身份证号",
          key: "identityNumber",
          align: "center",
          minWidth: 200,
          ellipsis: true, // 开启后，文本将不换行，超出部分显示为省略号
          tooltip: true // 鼠标放上去提示
        },
        {
          title: "所属部门",
          key: "departmentTitle",
          align: "center",
          minWidth: 200
        },
        {
          title: "手机号",
          key: "phone",
          align: "center",
          minWidth: 115
        },
        {
          title: "邮箱",
          key: "userEmail",
          align: "center",
          minWidth: 200
        },
        {
          title: "登录状态",
          key: "lockFlag",
          align: "center", // 设置剧中
          minWidth: 100,
          slot: "lockFlag" // 锁定标志   table 里回找到这个同名参数  进行关联
        },
        {
          title: "拒绝原因",
          key: "newDataId",
          align: "center", // 设置剧中
          minWidth: 160,
          slot: "newDataId" // 锁定标志   table 里回找到这个同名参数  进行关联
        },
        {
          title: "创建时间",
          key: "createTime",
          align: "center",
          sortable: true, // 排序
          minWidth: 180
        },
        {
          title: "操作",
          key: "action",
          minWidth: 180,
          align: "center",
          fixed: "right",
          slot: "action"
        }
      ],
      data: [],
      total: 0
    };
  },
  methods: {
    // 获取佣金和贷后的角色信息
    getCommissionLoan(){
      getCommissionLoan().then(res => {
        if (res.code === "0000") {
          console.log("长度+++++")
          if(res.data.length>0){
            for(var i=0;i<res.data.length;i++){
              if(res.data[i].roleCode=='ROLE_LOANAFTER'){
                this.loan=res.data[i].id;
              }else if(res.data[i].roleCode=='ROLE_COMMISSION'){
                 this.commission=res.data[i].id;
              }
            }
            console.log("佣金"+this.loan)
            console.log("贷后"+this.commission)
          }
        }
      });
    },
    // 获取登录者的用户id
    getUserId() {
      this.userId = this.$store.getters.userInfo.userId;
    },
    // 上传文件页面
    openFileUpload() {
       if(this.userForm.userId==null||this.userForm.userId==''||this.userForm.userId==undefined){
          this.$Message.error("请先保存信息后再上传附件！");
          return;
      }
           // 调后台获取json
      this.initGetFilterParams();
      console.log(this.isShowFile);
      this.isShowFile = !this.isShowFile;
    },
    // 获取附件数据
    initGetFilterParams() {
      console.log(this.userForm.userId)
            this.uploadParam.busiNo = this.userForm.userId;
            this.uploadParam.belongNo = this.userForm.userId;
            this.uploadParam.busiData = {};
            this.uploadParam.busiType = "dealerUser";
            this.canUpload=true;
        },
    // 初始化调用方法  这个应该是查询部门的
    initDepartmentData() {
      getDeptByParentId("0").then(res => {
        if (res.code === "0000") {
          res.data.forEach(function(e) {
            if (e.isParent) {
              e.value = e.id;
              e.label = e.title;
              e.loading = false;
              e.children = [];
            } else {
              e.value = e.id;
              e.label = e.title;
            }
            if (e.status === "0") {
              e.label = "[已禁用] " + e.title;
              e.title = "[已禁用] " + e.title;
              e.disabled = true;
            }
          });
          this.department = res.data;
        }
      });
    },

    // 点击搜索的部门树
    handleChangeDep(value) {
      console.log(value);
      // 获取最后一个值
      if (value && value.length > 0) {
        this.searchForm.deptId = value[value.length - 1];
        // this.$refs.searchForm.setFiledValue("deptId", value[value.length - 1]);
      } else {
        this.searchForm.deptId = "";
      }
    },

    // 还是搜索部门用的
    loadData(item, callback) {
      getDeptByParentId(item.value).then(res => {
        if (res.code === "0000") {
          res.data.forEach(function(e) {
            if (e.isParent) {
              e.value = e.id;
              e.label = e.title;
              e.loading = false;
              e.children = [];
            } else {
              e.value = e.id;
              e.label = e.title;
            }
            if (e.status === "0") {
              e.label = "[已禁用] " + e.title;
              e.title = "[已禁用] " + e.title;
              e.disabled = true;
            }
          });
          item.children = res.data;
          callback();
        }
      });
    },

    // 添加那边的部门树用的
    clearSelectDep() {
      this.userForm.deptId = "";
      this.userForm.departmentTitle = "";
    },
    // 添加部门时候的搜索方法
    searchDp() {
      // 搜索部门
      if (this.searchKey!=null&&this.searchKey!=undefined&&this.searchKey!='') {
        channelSearch(this.searchKey).then(res => {
          if (res.code === "0000") {
            res.data.forEach(function(e) {
              if (e.isParent) {
                e.loading = false;
                e.children = [];
              }
              if (e.status === "0") {
                e.title = "[已禁用] " + e.title;
                e.disabled = true;
              }
            });
            this.department = res.data;
          }
        });
      } else {
        this.initDepartmentData();
      }
    },
    //  这个是属于添加的时候部门点击触发的事件
    loadDataTree(item, callback) {
      getDeptByParentId(item.id).then(res => {
        if (res.code === "0000") {
          res.data.forEach(function(e) {
            if (e.isParent) {
              e.loading = false;
              e.children = [];
            }
            if (e.status === "0") {
              e.title = "[已禁用] " + e.title;
              e.disabled = true;
            }
          });
          callback(res.data);
        }
      });
    },

    // 添加里搜索
    selectTree(v) {
      console.log(v);
      console.log(Object.prototype.hasOwnProperty);
      if (v.length > 0) {
        // 转换null为""
        for (let attr in v[0]) {
          if (v[0][attr] === null) {
            v[0][attr] = "";
          }
        }
        let str = JSON.stringify(v[0]);
        let data = JSON.parse(str);
        this.deptId = data.id; //这个是不是 关联角色选择
        this.userForm.deptId = data.id;
        this.userForm.departmentTitle = data.title;
        // 先判断是有新车并且有二手车
        if (v[0].newCarRegion.length > 0 && v[0].oldCarRegion.length > 0) {
          this.getMatchingRole("newCar");
          this.getRoleList("old");
        } else {
          // 这边是判断这个部门是新车还二手车
          if (
            !Object.prototype.hasOwnProperty.call(v[0], "newCarRegion") ||
            v[0].newCarRegion.length == 0
          ) {
            this.newRoleList = [];
            console.log("不是新车");
          } else {
            this.getRoleList("new");
            console.log("是新车");
          }
          if (
            !Object.prototype.hasOwnProperty.call(v[0], "oldCarRegion") ||
            v[0].oldCarRegion.length == 0
          ) {
            this.oldRoleList = [];
            console.log("不是二手车");
          } else {
            this.getRoleList("old");
            console.log("是二手车");
          }
        }
        // 这边去处理下佣金和贷后的数据id问题

      }
    },

    // 点击新车的下拉框
    loadNewRole(val) {
      if (val) {
        this.getRoleList("new");
      }
    },
    // 点击二手车下拉框
    loadOldRole(val) {
      if (val) {
        this.getRoleList("old");
      }
    },
    // 新车点击触发的事件
    chooseRole(data) {
      console.log("点击"+data)
      if (this.border.length > 0) {
        if (this.border.length > this.oldBorder.length) {
          let id = this.border[this.border.length - 1];
          console.log("我添加的id是：" + this.border[this.border.length - 1]);
          // 去查看新车的集合
          console.log("新车集合：" + this.newRoleList.length);
          console.log("二手车集合：" + this.oldRoleList.length);
          if (this.newRoleList.length > 0) {
            for (var i = 0; i < this.newRoleList.length; i++) {
              if (id == this.newRoleList[i].id) {
                console.log("编号代码" + this.newRoleList[i].roleCode);
                let code = this.newRoleList[i].roleCode;
                // 这边进去的是新车预录员  此时应该把新车申报员去掉
                if (code == "ROLE_XCRECORDED") {
                  for (var a = 0; a < this.newRoleList.length; a++) {
                    if (this.newRoleList[a].roleCode == "ROLE_XCAPPLY") {
                      var index = this.border.indexOf(this.newRoleList[a].id);
                      console.log("请问这是啥" + index);
                      console.log("我和新车申报员互斥");
                      if (index >= 0) {
                        this.border.splice(index, 1);
                      }
                    }
                  }
                } else if (code == "ROLE_XCAPPLY") {
                  // 这边如果是新车申报员  此时此刻应该把新车预录员去掉
                  for (var b = 0; b < this.newRoleList.length; b++) {
                    if (this.newRoleList[b].roleCode == "ROLE_XCRECORDED") {
                      var indexb = this.border.indexOf(this.newRoleList[b].id);
                      console.log("请问这是啥" + indexb);
                      console.log("我和新车预录员互斥");
                      if (indexb >= 0) {
                        this.border.splice(indexb, 1);
                      }
                    }
                  }
                } else if (code == "ROLE_XCPREPAYMENT") {
                  // 如果是预防员   此时此刻应该把新车放款单员去掉
                  for (var c = 0; c < this.newRoleList.length; c++) {
                    if (this.newRoleList[c].roleCode == "ROLE_XCPAYMENT") {
                      var indexc = this.border.indexOf(this.newRoleList[c].id);
                      console.log("请问这是啥" + indexc);
                      console.log("我和新车放款报单员互斥");
                      if (indexc >= 0) {
                        this.border.splice(indexc, 1);
                      }
                    }
                  }
                } else if (code == "ROLE_XCPAYMENT") {
                  console.log("我是新车放款员")
                  console.log(this.newRoleList)
                  // 如果是新车放款单员  此时此刻应该去掉预防员
                  for (var d = 0; d < this.newRoleList.length; d++) {
                    console.log(this.newRoleList[d].roleCode)
                    console.log('ROLE_XCPREPAYMENT')
                    if (this.newRoleList[d].roleCode == "ROLE_XCPREPAYMENT") {
                      var indexd = this.border.indexOf(this.newRoleList[d].id);
                      console.log("请问这是啥" + indexd);
                      console.log("我和新车预防款员互斥");
                      if (indexd >= 0) {
                        this.border.splice(indexd, 1);
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      // 看看 有没有佣金贷后
      var qew = this.border.indexOf(this.loan);
      if (qew >= 0) {
          var asd = this.tBorder.indexOf(this.loan);
          if(asd>=0){

          }else{
            console.log("添加贷后")
            this.tBorder.push(this.loan);
          }
          
        }else{
          var asdf = this.tBorder.indexOf(this.loan);
          if(asdf>=0){
            console.log("我要移除贷后")
            this.tBorder.splice(asdf, 1);
          }
         
        }
        // 这边去处理佣金
        var qewa = this.border.indexOf(this.commission);
        if (qewa >= 0) {
            var asda = this.tBorder.indexOf(this.commission);
            if(asda>=0){

            }else{
              console.log("添加佣金")
              this.tBorder.push(this.commission);
            }
          
        }else{
          var asdfa = this.tBorder.indexOf(this.commission);
          if(asdfa>=0){
            console.log("我要移除贷后")
            this.tBorder.splice(asdfa, 1);
          }
         
        }

      this.tOldBorder = this.tBorder;
      this.userForm.oldRoleIds = this.tBorder;
      
      console.log("二手车全部集合"+this.tBorder)
      this.oldBorder = this.border;
      this.userForm.newRoleIds = this.border;
      console.log(this.border);
    },
    // 二手车点击触发的事件
    chooseOldRole() {
      if (this.tBorder.length > 0) {
        if (this.tBorder.length > this.tOldBorder.length) {
          let id = this.tBorder[this.tBorder.length - 1];
          console.log(
            "我添加的二手车id是：" + this.tBorder[this.tBorder.length - 1]
          );
          // 下面的是二手车
          if (this.oldRoleList.length > 0) {
            for (var j = 0; j < this.oldRoleList.length; j++) {
              console.log(this.oldRoleList[j].id);
              if (id == this.oldRoleList[j].id) {
                console.log("编号代码" + this.oldRoleList[j].roleCode);
                let code = this.oldRoleList[j].roleCode;
                // 这边进去的是二手车预录员  此时应该把二手车申报员去掉
                if (code == "ROLE_RECORDED") {
                  for (var e = 0; e < this.oldRoleList.length; e++) {
                    if (this.oldRoleList[e].roleCode == "ROLE_APPLY") {
                      var indexe = this.tBorder.indexOf(this.oldRoleList[e].id);
                      console.log("请问这是啥" + indexe);
                      console.log("我和二手车申报员互斥");
                      if (indexe >= 0) {
                        this.tBorder.splice(indexe, 1);
                      }
                    }
                  }
                } else if (code == "ROLE_APPLY") {
                  // 这边如果是二手车申报员  此时此刻应该把二手车预录员去掉
                  for (var f = 0; f < this.oldRoleList.length; f++) {
                    if (this.oldRoleList[f].roleCode == "ROLE_RECORDED") {
                      var indexf = this.tBorder.indexOf(this.oldRoleList[f].id);
                      console.log("请问这是啥" + indexf);
                      console.log("我和二手车预录员互斥");
                      if (indexf >= 0) {
                        this.tBorder.splice(indexf, 1);
                      }
                    }
                  }
                } else if (code == "ROLE_PREPAYMENT") {
                  // 如果是二手车预防员   此时此刻应该把二手车放款单员去掉
                  for (var g = 0; g < this.oldRoleList.length; g++) {
                    if (this.oldRoleList[g].roleCode == "ROLE_PAYMENT") {
                      var indexg = this.tBorder.indexOf(this.oldRoleList[g].id);
                      console.log("请问这是啥" + indexg);
                      console.log("我和二手车车放款报单员互斥");
                      if (indexg >= 0) {
                        this.tBorder.splice(indexg, 1);
                      }
                    }
                  }
                } else if (code == "ROLE_PAYMENT") {
                  // 如果是二手车放款单员  此时此刻应该去掉二手车预防员
                  for (var h = 0; h < this.oldRoleList.length; h++) {
                    if (this.oldRoleList[h].roleCode == "ROLE_PREPAYMENT") {
                      var indexh = this.tBorder.indexOf(this.oldRoleList[h].id);
                      console.log("请问这是啥" + indexh);
                      console.log("我和二手车预防款员互斥");
                      if (indexh >= 0) {
                        this.tBorder.splice(indexh, 1);
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      // 看看 有没有佣金贷后
      var qew = this.tBorder.indexOf(this.loan);
      if (qew >= 0) {
          var asd = this.border.indexOf(this.loan);
          if(asd>=0){

          }else{
            console.log("添加贷后")
            this.border.push(this.loan);
          }
          
        }else{
          var asdf = this.border.indexOf(this.loan);
          if(asdf>=0){
            console.log("我要移除贷后")
            this.border.splice(asdf, 1);
          }
         
        }
        // 这边去处理佣金
        var qewa = this.tBorder.indexOf(this.commission);
        if (qewa >= 0) {
            var asda = this.border.indexOf(this.commission);
            if(asda>=0){

            }else{
              console.log("添加佣金")
              this.border.push(this.commission);
            }
          
        }else{
          var asdfa = this.border.indexOf(this.commission);
          if(asdfa>=0){
            console.log("我要移除贷后")
            this.border.splice(asdfa, 1);
          }
         
        }
      this.oldBorder = this.border;
      this.userForm.newRoleIds = this.border;
      console.log("新车集合"+this.border);
      this.tOldBorder = this.tBorder;
      this.userForm.oldRoleIds = this.tBorder;
      console.log("二手车集合"+this.tBorder)
    },
    getone(v) {
      return true;
    },
    // 角色调的方法
    getRoleList(val) {
      console.log();
      if (!this.deptId) {
        this.$Message.warning("请先选择所属部门");
        return false;
      }
      getApplyAllList(val).then(res => {
        if (res.code === "0000") {
          if (val == "new") {
            this.newRoleList = res.data;
          } else if (val == "old") {
            this.oldRoleList = res.data;
          }
        }
      });
    },

    // 匹配单独的新车或者二手车
    getMatchingRole(val) {
      console.log();
      if (!this.deptId) {
        this.$Message.warning("请先选择所属部门");
        return false;
      }
      getMatchingRole(val).then(res => {
        if (res.code === "0000") {
          this.newRoleList = res.data;
        }
      });
    },

    // 这个是关闭弹窗
    cancelUser() {
      this.userModalVisible = false;
    },
    // 点击提交
    submitUser() {
      if(this.userForm.newRoleIds==0&&this.userForm.oldRoleIds==0){
         this.$Message.warning("至少选择一个角色！");
        return ;
      }
      this.$refs.userForm.validate(valid => {
        if (valid) {
          // 如果有 佣金角色和贷后角色  要二个都赋值
          // if (
          //   this.userForm.newRoleIds.length > 0 &&
          //   this.userForm.oldRoleIds.length > 0
          // ) {
          //   if (this.oldRoleList.length > 0) {
          //     for (var i = 0; i < this.oldRoleList.length; i++) {
          //       // 找到贷后角色id
          //       if (this.oldRoleList[i].roleCode == "ROLE_LOANAFTER") {
          //         if (this.userForm.oldRoleIds.length > 0) {
          //           for (var a = 0; a < this.userForm.oldRoleIds.length; a++) {
          //             if (
          //               this.oldRoleList[i].id == this.userForm.oldRoleIds[a]
          //             ) {
          //               // 把id 也给到新车
          //               this.userForm.newRoleIds.push(
          //                 this.userForm.oldRoleIds[a]
          //               );
          //             }
          //           }
          //         }
          //       }
          //       // 找到佣金角色
          //       if (this.oldRoleList[i].roleCode == "ROLE_COMMISSION") {
          //         if (this.userForm.oldRoleIds.length > 0) {
          //           for (var b = 0; b < this.userForm.oldRoleIds.length; b++) {
          //             if (
          //               this.oldRoleList[i].id == this.userForm.oldRoleIds[b]
          //             ) {
          //               // 把id 也给到新车
          //               this.userForm.newRoleIds.push(
          //                 this.userForm.oldRoleIds[b]
          //               );
          //             }
          //           }
          //         }
          //       }
          //     }
          //   }
          // } else if (this.userForm.newRoleIds.length > 0) {
          //   console.log("我进来新车了");
          //   // 只有新车角色
          //   if (this.newRoleList.length > 0) {
          //     for (var j = 0; j < this.newRoleList.length; j++) {
          //       // 找到贷后角色id
          //       if (this.newRoleList[j].roleCode == "ROLE_LOANAFTER") {
          //         console.log("有的贷后");
          //         if (this.userForm.newRoleIds.length > 0) {
          //           console.log("有的贷后2222");
          //           for (var c = 0; c < this.userForm.newRoleIds.length; c++) {
          //             console.log("多少" + this.userForm.newRoleIds[c]);
          //             if (
          //               this.newRoleList[j].id == this.userForm.newRoleIds[c]
          //             ) {
          //               console.log("我要放进二手车");
          //               // 把id 也给到新车
          //               this.userForm.oldRoleIds.push(
          //                 this.userForm.newRoleIds[c]
          //               );
          //             }
          //           }
          //         }
          //       }
          //       // 找到佣金角色
          //       if (this.newRoleList[j].roleCode == "ROLE_COMMISSION") {
          //         console.log("有的佣金角色");
          //         if (this.userForm.newRoleIds.length > 0) {
          //           for (var d = 0; d < this.userForm.newRoleIds.length; d++) {
          //             if (
          //               this.newRoleList[j].id == this.userForm.newRoleIds[d]
          //             ) {
          //               // 把id 也给到新车
          //               this.userForm.oldRoleIds.push(
          //                 this.userForm.newRoleIds[d]
          //               );
          //             }
          //           }
          //         }
          //       }
          //     }
          //   }
          // }
          // 校验黑名单
          let params = {
              blacklistType: '03',
              idType: '01',
              idCode: this.userForm.identityNumber,
          }
          checkBlack(params).then(res => {
              if (res.code === "0000") {
                  if (res.weatherBlackList == "0") {
                      if (this.modalType === 0) {
            addUser(this.userForm)
              .then(res => {
                if (res.code === "0000") {
                  this.$Message.success(res.msg);
                  this.userModalVisible = false;
                  this.handleReset();
                }
              })
              .catch(() => {
                this.handleReset();
              });
          } else {
            // 编辑
            editUserTemp(this.userForm)
              .then(res => {
                if (res.code === "0000") {
                  this.$Message.success(res.msg);
                  this.userModalVisible = false;
                  this.handleReset();
                }
              })
              .catch(() => {
                this.handleReset();
              });
          }
                  }else{
                    this.$Message.error("见证人数据异常");
                  }
              }
          });

        }else{
           this.$Message.warning("请补充信息！");
        }
      });
    },

    // 部门的清空事件
    //channelClear 点击清空事件
    channelClear() {
      this.oldRoleList = [];
      this.newRoleList = [];
      console.log("我要情况");
    },

    // 搜索的部门清空
    clearDepId(){
      this.searchForm.deptId="";
      this.searchForm.any=[];
    },
    //  初始化调用方法
    queryData() {
      let queryData = {
        condition: this.searchForm,
        pageNumber: this.searchForm.pageNumber,
        pageSize: this.searchForm.pageSize
      };
      getUserListDataTemp(queryData).then(res => {
        this.loading = false;
        if (res.code === "0000") {
          this.data = res.data.records;
          this.total = res.data.total;
          // this.$refs.userTable.updateTableData(records, total);
        }
      });
    },
    // 点击下面分页调用的方法
    changePage(v) {
      this.searchForm.pageNumber = v;

      this.queryData();
      this.clearSelectAll();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;

      this.queryData();
    },
    // 时间选择器调用的
    selectDateRange(v) {
      if (v) {
        this.searchForm.startDate = v[0] + " 00:00:00";
        this.searchForm.endDate = v[1] + " 23:59:59";
      }
    },
    // 获取数据字典
    getChannelStatus() {
      let param = {
        type: "effectiveStatus"
      };
      getDictDataByType(param.type).then(res => {
        if (res.code === "0000") {
        }
      });
    },

    // 点击搜索调用的方法
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.queryData();
    },
    // 重置搜索
    handleReset() {
      this.$refs.searchForm.resetFields();
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.selectDate = null;
      this.searchForm.startDate = "";
      this.searchForm.endDate = "";
      this.searchForm.deptId="";
      this.searchForm.any=[];

      this.queryData();
    },
    // 点击列表时间
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order === "normal") {
        this.searchForm.order = "";
      }
    },

    // 点击添加
    add() {
      this.initDepartmentData();
      this.userForm.userId = "";
      this.userForm.userRealName = ""; // 真实姓名
      this.userForm.departmentTitle = ""; // 部门的名字
      this.userForm.deptId = ""; //所属部门id
      this.userForm.username = ""; //用户名
      this.userForm.userEmail = ""; // 邮箱
      this.userForm.phone = ""; // 手机号
      this.userForm.identityNumber = ""; //身份证号
      this.userForm.newRoleIds = []; // 新车的角色集合
      this.userForm.oldRoleIds = []; //二手车的角色集合
      this.oldRoleList = []; //二手车角色集合
      this.newRoleList = []; // 新车角色集合

      this.border=[];
      this.tBorder=[];
      this.oldBorder=[];
      this.tOldBorder=[];

      this.modalType = 0;
      this.modalTitle = "添加用户";
      this.$refs.userForm.resetFields();
      this.userModalVisible = true;
    },
    // 点击编辑
    edit(v) {
      if (this.$store.getters.userInfo.userId === v.userId) {
        this.$Message.success("不能修改自己的账户！！！");
        return false;
      }
      if(v.newStatus=='01'||v.newStatus=='10'||v.oldStatus=='01'||v.oldStatus=='10'){
        this.see(v)
      }else{
        this.initDepartmentData();
        console.log(v)
        // 下面这些是为了先清空数据
        this.userForm.userId = "";
        this.userForm.userRealName = ""; // 真实姓名
        this.userForm.departmentTitle = ""; // 部门的名字
        this.userForm.deptId = ""; //所属部门id
        this.userForm.username = ""; //用户名
        this.userForm.userEmail = ""; // 邮箱
        this.userForm.phone = ""; // 手机号
        this.userForm.identityNumber = ""; //身份证号
        this.userForm.newRoleIds = []; // 新车的角色集合
        this.userForm.oldRoleIds = []; //二手车的角色集合
        this.oldRoleList = []; //二手车角色集合
        this.newRoleList = []; // 新车角色集合
        this.border=[];
        this.oldBorder=[];
        this.tBorder=[];
        this.tOldBorder=[];

        this.modalType = 1;
        this.modalTitle = "用户编辑";
        this.deptId = v.deptId;
        this.userForm.deptId=v.deptId;
        this.userForm.departmentTitle = v.departmentTitle;
        this.userForm.userRealName = v.userRealName;
        this.userForm.username = v.username;
        this.userForm.userId = v.userId;
        this.userForm.identityNumber = v.identityNumber;
        this.userForm.userEmail = v.userEmail;
        this.userForm.phone = v.phone;

        // 去调用图片信息
        this.showCarImg()

        let size = []; // 声明一个贷后和佣金的集合

        // 新车拥有的集合
        if (v.newRoles.length > 0) {
          for (var i = 0; i < v.newRoles.length; i++) {
            if (v.newRoles[i].roleCode == "ROLE_LOANAFTER"||v.newRoles[i].roleCode=="ROLE_COMMISSION" ) {
              var indexh = size.indexOf(v.newRoles[i].id);
              console.log("看看我有没有"+indexh)
              if (indexh == -1) {
                 size.push(v.newRoles[i].id);
              }

            } else {
              this.userForm.newRoleIds.push(v.newRoles[i].id);
            }
          }
        }
        // 二手车
        if(v.oldRoles.length>0){
          for (var j = 0; j < v.oldRoles.length; j++) {
            console.log("code码是多少"+v.oldRoles[j].roleCode)
            if (v.oldRoles[j].roleCode == "ROLE_LOANAFTER"||v.oldRoles[j].roleCode=="ROLE_COMMISSION" ) {
              var index = size.indexOf(v.oldRoles[j].id);
              console.log("看看我有没有"+index)
              if (index == -1) {
                 size.push(v.oldRoles[j].id);
              }
            } else {
              this.userForm.oldRoleIds.push(v.oldRoles[j].id);
            }
          }
        }
        console.log("共有的长度"+size.length)
         // 根据 deptId 查询可以选择的角色id 集合
        getDeptByDeptId(v.deptId).then(res => {
          if (res.code === "0000") {
            if(res.data.newCarRegion.length>0&&res.data.oldCarRegion.length>0){
              this.getMatchingRole("newCar");
              this.getRoleList("old");
              if(size.length>0){
                for(var f=0;f<size.length;f++){
                  this.userForm.oldRoleIds.push(size[f]);
                }
                for(var ff=0;ff<size.length;ff++){
                  this.userForm.newRoleIds.push(size[ff]);
                }
              }
              this.border=this.userForm.newRoleIds;
              this.oldBorder=this.border;
              this.tBorder=this.userForm.oldRoleIds;
              this.tOldBorder=this.tBorder;
              console.log("二手车集合回显"+this.tBorder)

            }else if(res.data.newCarRegion.length>0){
              if(size.length>0){
                for(var yyy=0;yyy<size.length;yyy++){
                  this.userForm.oldRoleIds.push(size[yyy]);
                }
                for(var y=0;y<size.length;y++){
                  this.userForm.newRoleIds.push(size[y]);
                }
                
              }
              console.log("我有"+this.userForm.newRoleIds)
              // 只有新车
              this.getRoleList("new");
              this.border=this.userForm.newRoleIds;
              this.oldBorder=this.border;
              console.log("新车集合回显"+this.border)

            }else if(res.data.oldCarRegion.length>0){
              console.log("我要看看 共有的"+size)
              if(size.length>0){
                for(var z=0;z<size.length;z++){
                  this.userForm.oldRoleIds.push(size[z]);
                }
                for(var yyyy=0;yyyy<size.length;yyyy++){
                  this.userForm.newRoleIds.push(size[yyyy]);
                }
              }
              // 只有二手车
              this.getRoleList("old");
              this.tBorder=this.userForm.oldRoleIds;
              this.tOldBorder=this.tBorder;
              console.log("二手车集合回显"+this.tBorder)
            }
          }
        });
        // 最后请打开弹窗
        this.userModalVisible = true;
        console.log("最后打印下集合数据")
        console.log("新车集合"+this.newRoleList)
        console.log("我有的结合"+this.userForm.newRoleIds)
        console.log()
      }
    },
    //  查看
    see(v){
      this.initDepartmentData();
      console.log(v)
      // 下面这些是为了先清空数据
      this.userForm.userId = "";
      this.userForm.userRealName = ""; // 真实姓名
      this.userForm.departmentTitle = ""; // 部门的名字
      this.userForm.deptId = ""; //所属部门id
      this.userForm.username = ""; //用户名
      this.userForm.userEmail = ""; // 邮箱
      this.userForm.phone = ""; // 手机号
      this.userForm.identityNumber = ""; //身份证号
      this.userForm.newRoleIds = []; // 新车的角色集合
      this.userForm.oldRoleIds = []; //二手车的角色集合
      this.oldRoleList = []; //二手车角色集合
      this.newRoleList = []; // 新车角色集合
      this.border=[];
      this.oldBorder=[];
      this.tBorder=[];
      this.tOldBorder=[];

      if (this.$store.getters.userInfo.userId === v.userId) {
        this.$Message.success("不能查看自己的账户！！！");
        return false;
      }
      this.modalType = 1;
      this.modalTitle = "用户查看";
      this.deptId = v.deptId;
      this.userForm.deptId=v.deptId;
      this.userForm.departmentTitle = v.departmentTitle;
      this.userForm.userRealName = v.userRealName;
      this.userForm.username = v.username;
      this.userForm.userId = v.userId;
      this.userForm.identityNumber = v.identityNumber;
      this.userForm.userEmail = v.userEmail;
      this.userForm.phone = v.phone;

      // 去调用图片信息
      this.showCarImg()

      let size = []; // 声明一个贷后和佣金的集合

      // 新车拥有的集合
      if (v.newRoles.length > 0) {
        for (var i = 0; i < v.newRoles.length; i++) {
          if (v.newRoles[i].roleCode == "ROLE_LOANAFTER"||v.newRoles[i].roleCode=="ROLE_COMMISSION" ) {
            var indexh = size.indexOf(v.newRoles[i].id);
            console.log("看看我有没有"+indexh)
            if (indexh == -1) {
               size.push(v.newRoles[i].id);
            }

          } else {
            this.userForm.newRoleIds.push(v.newRoles[i].id);
          }
        }
      }
      // 二手车
      if(v.oldRoles.length>0){
        for (var j = 0; j < v.oldRoles.length; j++) {
          console.log("code码是多少"+v.oldRoles[j].roleCode)
          if (v.oldRoles[j].roleCode == "ROLE_LOANAFTER"||v.oldRoles[j].roleCode=="ROLE_COMMISSION" ) {
            var index = size.indexOf(v.oldRoles[j].id);
            console.log("看看我有没有"+index)
            if (index == -1) {
               size.push(v.oldRoles[j].id);
            }
          } else {
            this.userForm.oldRoleIds.push(v.oldRoles[j].id);
          }
        }
      }
      console.log("共有的长度"+size.length)
       // 根据 deptId 查询可以选择的角色id 集合
      getDeptByDeptId(v.deptId).then(res => {
        if (res.code === "0000") {
          if(res.data.newCarRegion.length>0&&res.data.oldCarRegion.length>0){
            this.getMatchingRole("newCar");
            this.getRoleList("old");
            if(size.length>0){
              for(var f=0;f<size.length;f++){
                this.userForm.oldRoleIds.push(size[f]);
              }
            }
            this.border=this.userForm.newRoleIds;
            this.oldBorder=this.border;
            this.tBorder=this.userForm.oldRoleIds;
            this.tOldBorder=this.tBorder;
            console.log("二手车集合回显"+this.tBorder)

          }else if(res.data.newCarRegion.length>0){
            if(size.length>0){
              for(var y=0;y<size.length;y++){
                this.userForm.newRoleIds.push(size[y]);
              }
            }
            console.log("我有"+this.userForm.newRoleIds)
            // 只有新车
            this.getRoleList("new");
            this.border=this.userForm.newRoleIds;
            this.oldBorder=this.border;
            console.log("新车集合回显"+this.border)

          }else if(res.data.oldCarRegion.length>0){
            console.log("我要看看 共有的"+size)
            if(size.length>0){
              for(var z=0;z<size.length;z++){
                this.userForm.oldRoleIds.push(size[z]);
              }
            }
            // 只有二手车
            this.getRoleList("old");
            this.tBorder=this.userForm.oldRoleIds;
            this.tOldBorder=this.tBorder;
            console.log("二手车集合回显"+this.tBorder)
          }
        }
      });
      // 最后请打开弹窗
      this.userModalVisibleSee = true;
      console.log("最后打印下集合数据")
      console.log("新车集合"+this.newRoleList)
      console.log("我有的结合"+this.userForm.newRoleIds)
      console.log()
    },

    // table  里的搜索
    showSelect(e) {
      console.log(e);
      this.selectList = e;
      this.selectCount = e.length;
    },
    //  点击清空的方法
    clearSelectAll() {
      this.$refs.table.selectAll(false);
    },

    // 批量删除
    upAll() {
      if (this.selectCount <= 0) {
        this.$Message.warning("您还未选择要停用的数据");
        return;
      }
      for (var i = 0; i < this.selectList.length; i++) {
        if (this.$store.getters.userInfo.userId === this.selectList[i].userId) {
          this.$Message.success("不能禁用自己的账户！！！");
          return false;
        }
        if(this.selectList[i].lockFlag=='9'){
          this.$Message.success("存在已禁用用户，请重新选择！");
          return false;
        }
      }
      //   for (var i = 0; i < this.selectList.length; i++) {
      //     if (this.selectList[i].status != "00") {
      //       this.$Message.warning("只有启用的才可以停用，请重新选择！");
      //       this.clearSelectAll();
      //       return;
      //     }
      //   }
      this.$Modal.confirm({
        title: "确认停用",
        content: "您确认要停用所选的 " + this.selectCount + " 条数据?",
        onOk: () => {
          let ids = [];
          this.selectList.forEach(function(e) {
            ids += e.userId + ",";
          });
          ids = ids.substring(0, ids.length - 1);
          this.operationLoading = true;
          upAllByIds(ids).then(res => {
            this.operationLoading = false;
            if (res.code === "0000") {
              this.$Message.success("停用成功");
              this.clearSelectAll();
              this.handleReset();
            }
          });
        }
      });
    },
    // 重置密码v
    passWord(v){
      this.$Modal.confirm({
        title: "确认停用",
        content: "您确认要重置用户名为 " + v.username + " 的账号吗?",
        onOk: () => {
          this.operationLoading = true;
          passWord(v.userId).then(res => {
            this.operationLoading = false;
            if (res.code === "0000") {
              this.$Message.success("重置成功");
              this.handleReset();
            }
          });
        }
      });

    },
    // 获取这个渠道的所有用户角色列表
    getUserRole(){
      console.log("我被调用了");
      getUserRole().then(res => {
        if (res.code === "0000") {
          this.userRole = res.data;
        }
      });
    },
    //遍历获取单个用户的角色
    getThisRole(id){
      let role=[];
      if(this.userRole.length>0){
        for(var i=0;i<this.userRole.length;i++){
          if(id==this.userRole[i].userId){
            if(role.indexOf(this.userRole[i].roleName) == -1){
            role.push(this.userRole[i].roleName)
         }

          }
        }
      }
      return role;
    },


    // 下面是上传身份证
    getImg(event,type) {
      console.log("点击上传")
                let files = event.target.files;
                console.log(files,"files")
                let AllUpExt = ".jpg|.bmp|.jpeg|.png|.gif|";
                let extName = files[0].name.substring(files[0].name.lastIndexOf(".")).toLowerCase();
                if (AllUpExt.indexOf(extName + "|") == "-1") {
                    this.$Message.warning("文件格式不正确！");
                    return;
                }

                let size = files[0].size;
                size = size / (1024 * 1024);
                console.log(size)
                if (size > 10) {  // 10M
                    this.$Message.warning("文件过大");
                    return;
                }

                let file = files[0];
                let formData = new FormData();//创建 formdata对象
                formData.append('file', file);
                uploadFile(formData).then(res => {
                    if (res.code === "0000") {
                       this.uploadFiles(res.data,type)
                    } else {
                        this.$Message.error("图片转md5失败");
                    }
                });

            },
            uploadFiles(data,type){
                let typeimg=type=='zm'?this.frontType:this.balckType
                let params = {
                    "map": data,
                    // "type": typeimg,
                    // "busiNo": this.tempBusiNo
                }
                uploadRealFile(params).then(res => {
                    if (res.code === "0000") {
                        this.$Message.success("图片上传成功");
                        // let  _URL = window.URL || window.webkitURL;
                        // let tempUrl=_URL.createObjectURL(file)
                        let obj={
                            map:data,
                        };
                        console.log("222222222"+data)
                        console.log("333333"+typeimg)
                        this.userForm.finalimgList[0].fileName=data.fileName;
                        this.userForm.finalimgList[0].isFastDFS=data.isFastDFS;
                        this.userForm.finalimgList[0].md5=data.md5;
                        this.userForm.finalimgList[0].size=data.size;
                        this.userForm.finalimgList[0].suffix=data.suffix;
                        // if(this.userForm.finalimgList.length>0){
                        //   console.log("到底是哪个")
                        //     this.userForm.finalimgList.forEach((item,index)=>{
                        //             this.userForm.finalimgList[index].map=data;
                        //             this.userForm.finalimgList[index].map.type=typeimg;

                        //     })
                        // }else{
                        //   console.log("这个"+obj.map)
                        //     obj.map.type=typeimg;
                        //     this.userForm.finalimgList.push(obj.map);
                        // }
                        console.log(this.userForm.finalimgList[0],"finalimgList")
                        if(type=="zm"){
                            this.userForm.imgzurl="data:image/jpeg;base64,"+res.data;
                            this.$refs.img_z.value="";
                        }
                        // 调用OCR
                        if(this.userForm.userId==''||this.userForm.userId==null||this.userForm.userId==undefined){
                          this.getOCRInfo();
                        }
                        console.log("imgzurl地址"+this.userForm.imgzurl)
                    } else {
                        this.$Message.error("图片上传失败");
                    }
                });
            },
            zhengmian(){
                if(this.isPass){
                    return false;
                }
                this.$refs.img_z.click();
            },
            fanmian(){
                if(this.isPass){
                    return false;
                }
                this.$refs.img_f.click();
            },
            showCarImg(){
              console.log("读取图片")
                let params = {
                    "busiNo": this.userForm.userId,
                }
                getUserPhotoByMD5(params).then(res => {
                    if (res.code === "0000") {
                      this.userForm.finalimgList[0].fileName=res.data.fileName;
                      this.userForm.finalimgList[0].isFastDFS=res.data.isFastDFS;
                      this.userForm.finalimgList[0].md5=res.data.fileId;
                      this.userForm.finalimgList[0].size=res.data.size;
                      this.userForm.finalimgList[0].suffix=res.data.fileType;
                      this.userForm.imgzurl  = `${_AFS_PROJECT_CONFIG.apiUri}/${getUri('image')}/upload/getBlob/${res.data.fileType}/${res.data.fileId}`;
                    } else {
                        this.$Message.error("图片获取失败");
                    }
                });
            },
            // OCR读取图片
            getOCRInfo(){
              console.log("读取图片")
                let params = {
                    "caseCode":this.userForm.finalimgList[0].md5,
                    "inletEnd": "PC",
                    "sysCode":"WOW",
                    "fileCode":"idCardFront",
                    "fileMd5":this.userForm.finalimgList[0].md5,
                    "ispCode":"baidu"
                }
                getOCRInfo(params).then(res => {
                    if (res.code === "0000") {
                      this.userForm.userRealName=res.data.name;
                      this.userForm.identityNumber=res.data.number;
                    } else {
                        this.$Message.error("OCR识别失败！");
                    }
                });
            },
            devierimglist(){
                return this.userForm.finalimgList;
            },
            resetimgurl(){
                this.userForm.imgzurl="";
                this.userForm.imgfurl="";
            }
  },
  // 初始化加载的方法
  mounted() {
    //this.refresh();
    this.initDepartmentData();
    this.queryData();
    this.getUserId();
    this.getUserRole();
    this.getCommissionLoan();
  }
};
</script>
